package com.triz.business.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.triz.common.annotation.Log;
import com.triz.common.core.controller.BaseController;
import com.triz.common.core.domain.AjaxResult;
import com.triz.common.enums.BusinessType;
import com.triz.business.domain.ComponentAnalysis;
import com.triz.business.service.IComponentAnalysisService;
import com.triz.common.utils.poi.ExcelUtil;
import com.triz.common.core.page.TableDataInfo;

/**
 * 组件分析Controller
 * 
 * @author hlk
 * @date 2025-11-13
 */
@RestController
@RequestMapping("/business/componentAnalysis")
public class ComponentAnalysisController extends BaseController
{
    @Autowired
    private IComponentAnalysisService componentAnalysisService;

    /**
     * 查询组件分析列表
     */
//    @PreAuthorize("@ss.hasPermi('business:componentAnalysis:list')")
    @GetMapping("/list")
    public TableDataInfo list(ComponentAnalysis componentAnalysis)
    {
        startPage();
        List<ComponentAnalysis> list = componentAnalysisService.selectComponentAnalysisList(componentAnalysis);
        return getDataTable(list);
    }

    /**
     * 导出组件分析列表
     */
//    @PreAuthorize("@ss.hasPermi('business:componentAnalysis:export')")
    @Log(title = "组件分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ComponentAnalysis componentAnalysis)
    {
        List<ComponentAnalysis> list = componentAnalysisService.selectComponentAnalysisList(componentAnalysis);
        ExcelUtil<ComponentAnalysis> util = new ExcelUtil<ComponentAnalysis>(ComponentAnalysis.class);
        util.exportExcel(response, list, "组件分析数据");
    }

    /**
     * 获取组件分析详细信息
     */
//    @PreAuthorize("@ss.hasPermi('business:componentAnalysis:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(componentAnalysisService.selectComponentAnalysisById(id));
    }

    /**
     * 新增组件分析
     */
//    @PreAuthorize("@ss.hasPermi('business:componentAnalysis:add')")
    @Log(title = "组件分析", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComponentAnalysis componentAnalysis)
    {
        componentAnalysis.setCreateBy(getUsername());
        return toAjax(componentAnalysisService.insertComponentAnalysis(componentAnalysis));
    }

    /**
     * 修改组件分析
     */
//    @PreAuthorize("@ss.hasPermi('business:componentAnalysis:edit')")
    @Log(title = "组件分析", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ComponentAnalysis componentAnalysis)
    {
        componentAnalysis.setUpdateBy(getUsername());
        return toAjax(componentAnalysisService.updateComponentAnalysis(componentAnalysis));
    }

    /**
     * 删除组件分析
     */
    @PreAuthorize("@ss.hasPermi('business:componentAnalysis:remove')")
    @Log(title = "组件分析", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(componentAnalysisService.deleteComponentAnalysisByIds(ids));
    }





    /**
     * 查找有相互作用力关系的组件
     * projectId
     * createBy
     */
    @PostMapping("/queryComponentAnalysisList")
    public TableDataInfo queryComponentAnalysisList(@RequestBody Map<String, Object> map)
    {
        List<ComponentAnalysis> list = componentAnalysisService.queryComponentAnalysisList(map);
        return getDataTable(list);
    }

    /**
     * 查找有相互作用力关系的目标组件
     * projectId
     * sourceId
     * createBy
     */
    @PostMapping("/selectInteractionList")
    public TableDataInfo selectInteractionList(@RequestBody Map<String, Object> map)
    {
        List<ComponentAnalysis> list = componentAnalysisService.selectInteractionList(map);
        return getDataTable(list);
    }
}
